package com.cisco.vsx.email.util;

import java.util.ArrayList;
import java.util.List;

import com.cisco.vsx.email.Event;
import com.cisco.vsx.email.Template;
import com.cisco.vsx.email.entities.EmailEventEntity;
import com.cisco.vsx.email.entities.EmailTemplateEntity;

/**
 * @author naresred
 *
 */
public class BeanTransformer {
	
	public static Template transform(EmailTemplateEntity emailTemplateEntity) {
		Template template = new Template();
		
		template.setId(emailTemplateEntity.getId());
		template.setName(emailTemplateEntity.getName());
		template.setDescription(emailTemplateEntity.getDescription());
		template.setContent(emailTemplateEntity.getContent());
		template.setLocale(emailTemplateEntity.getLocale());
		template.setActive(emailTemplateEntity.getActive() == 1 ? true : false);
		template.setDefaultTemplate(emailTemplateEntity.getDefaultTemplate() == 1 ? true : false);
		
		if (emailTemplateEntity.getEmailEvent() != null)
			template.setEvent(transform(emailTemplateEntity.getEmailEvent()));
		
		return template;
	}
	
	public static List<Template> transform(List<EmailTemplateEntity> templateEntityList) {
		List<Template> templateList = new ArrayList<Template>();
		for (EmailTemplateEntity te : templateEntityList) {
			templateList.add(transform(te));
		}
		
		return templateList;
	}

	public static Event transform(EmailEventEntity ev) {
		Event event = new Event();
		
		event.setEventName(ev.getName());
		event.setEventDescription(ev.getDescription());
		event.setEventId(ev.getId());
		event.setActive(ev.getActive() == 1 ? true : false);
		event.setModelXml(ev.getModel());
		
		return event;
	}

	public static List<Event> transformEvents(List<EmailEventEntity> eventEntities) {
		List<Event> eventList = new ArrayList<Event>();
		for (EmailEventEntity ev : eventEntities) {
			eventList.add(transform(ev));
		}
		
		return eventList;
	}

}
